package com.zsr.config;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;
import springfox.documentation.builders.ApiInfoBuilder;
import springfox.documentation.builders.PathSelectors;
import springfox.documentation.builders.RequestHandlerSelectors;
import springfox.documentation.service.ApiInfo;
import springfox.documentation.service.Contact;
import springfox.documentation.spi.DocumentationType;
import springfox.documentation.spring.web.plugins.Docket;
import springfox.documentation.swagger2.annotations.EnableSwagger2;

import java.util.ArrayList;

/**
 * @Author zsr
 * @Desc
 * @Date 2021/5/26 21:25
 */
@Configuration
@EnableSwagger2 // 开启swagger2
public class SwaggerConfig {

    @Value("${swagger.show}")
    private boolean swaggerShow;

    //配置了swagger
    @Bean
    public Docket docket(){
        return new Docket(DocumentationType.SWAGGER_2)
                .enable(swaggerShow)//是否开启
                .apiInfo(apiInfo())
                .select()  //初始化并返回一个API选择构造器
                .apis(RequestHandlerSelectors.basePackage("com.zsr.controller"))//添加路径选择条件
                .paths(PathSelectors.any())//设置路径筛选
                .build();//构建
    }

    private ApiInfo apiInfo(){
        /*return new ApiInfo(
                "SwaggerDemo文档"
                , "描述.."
                , "1.0"
                , "urn:tos"
                , new Contact("zsrey", "", "1301888091@qq.com")
                , "Apache 2.0"
                , "http://www.apache.org/licenses/LICENSE-2.0"
                , new ArrayList());*/
        return new ApiInfoBuilder()
                .title("SwaggerDemo文档")
                .description("描述..")
                .termsOfServiceUrl("")
                .contact("zsrey")
                .version("1.0")
                .build();
    }
}
